package com.doraro.platform.genData;

import com.doraro.platform.common.utils.EncryptUtil;
import com.doraro.platform.module.user.model.entity.SysUser;
import com.doraro.platform.module.user.service.ISysUserService;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.time.LocalDateTime;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class GenData {
    @Autowired
    ISysUserService userService;

    @Test
    public void genAdmin() {
        final SysUser user = new SysUser();
        user.setCreateTime(LocalDateTime.now());
        user.setLastLoginTime(LocalDateTime.now());
        user.setUpdateTime(LocalDateTime.now());
        user.setLoginName("admin");
        user.setPassword("admin");
        user.setAvatar("");
        user.setNickName("admin");
        user.setIp("");
        user.setEmail("admin@qq.com");
        final String password = user.getPassword();
        String salt = RandomStringUtils.randomAlphabetic(36);
        String encode = EncryptUtil.getSha512(salt + ":" + password);
        user.setPassword(encode);
        user.setSalt(salt);
        user.setUserStatus(1);
        userService.save(user);
    }
}
